<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户添加页面</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <div class="row clearfix">
            <div class="col-md-offset-3 col-md-6">
                <div class="page-header">
                    <h2>
                        <small>
                            添加用户
                        </small>
                    </h2>
                </div>
            </div>
        </div>

        <div class="row clearfix">
            <div class="col-md-offset-3 col-md-6">
                <form action="${pageContext.request.contextPath}/user/userDo/add" method="post">
                    <div class="form-group">
                        <label for="userCode">用户编码：</label>
                        <input type="text" name="userCode" id="userCode" value="" class="form-control" required>
                        <!-- 放置提示信息 -->
                        <span id="tipsUserCode" style="color:red"></span>
                    </div>
                    <div class="form-group">
                        <label for="userName">用户名称：</label>
                        <input type="text" name="userName" id="userName" value="" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label for="userPassword">用户密码：</label>
                        <input type="password" name="userPassword" id="userPassword" value="" class="form-control" required>
                        <!-- 放置提示信息 -->
                        <span id="tipsuserPassword" style="color:red"></span>
                    </div>
                    <div class="form-group">
                        <label for="ruserPassword">确认密码：</label>
                        <input type="password" name="ruserPassword" id="ruserPassword" value="" class="form-control" onblur="pwdCheck()" required>
                        <!-- 放置提示信息 -->
                        <span id="tipsRuserPassword" style="color:red"></span>
                    </div>
                    <div class="form-group">
                        <label >用户性别：</label>
                        <select name="gender" id="gender" class="form-control">
                            <option value="1" selected="selected">男</option>
                            <option value="2">女</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="birthday">出生日期：</label>
                        <input type="date" id="birthday" name="birthday" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label for="phone">用户电话：</label>
                        <input type="text" name="phone" id="phone" value="" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label for="address">用户地址：</label>
                        <input name="address" id="address"  value="" class="form-control">
                    </div>
                    <div class="form-group">
                        <label >用户角色：</label>
                        <!-- 列出所有的角色分类 -->
                        <select name="userRole" id="userRole" class="form-control">
                            <option value="1">系统管理员</option>
                            <option value="2">经理</option>
                            <option value="3">普通员工</option>
                        </select>
                    </div>
                    <div class="form-inline">
                        <div  class="col-md-offset-4">
                            <input type="submit" class="btn btn-default" value="&emsp;保存&emsp;">
                            <button type="button" class="btn btn-default">
                                <a href="${pageContext.request.contextPath}/user/userDo/queryPage">
                                    &emsp;返回&emsp;
                                </a>
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="${pageContext.request.contextPath}/webjars/jquery/3.6.0/jquery.js"></script>
    <script>
        $(function () {
            $('#userCode').blur(function () {
                let userCode = $('#userCode').val();
                console.log(userCode);
                userCodeCheck(userCode);
            });
            $('#ruserPassword').blur(function (){
                pwdCheck();
            });
            $('#userPassword').blur(function (){
                let pwd = $('#userPassword').val();
                if (pwd.length<=6 || pwd.length>=13){
                    $('#tipsuserPassword').text("*密码请设置在7到12位(7<=num<=12)")
                }else{
                    $('#tipsuserPassword').text("")
                }
            });
        })

        //用户编码查重
        function userCodeCheck(rUserCode) {
            $.ajax({
                url:"${pageContext.request.contextPath}/user/register/checkUserCode",
                type:"POST",
                data:{
                    registerUserCode:rUserCode,
                    OperationName:'',
                    id:0
                },
                success:function (data) {
                    console.log(data);
                    if(!data){
                        $('#tipsUserCode').text("*用户编码重复")
                    }else{
                        $('#tipsUserCode').text("")
                    }
                }
            })
        }

        //确认密码
        function pwdCheck() {
            let pwd = $('#userPassword').val();
            let rpwd = $('#ruserPassword').val();
            console.log('pwdCheck');
            if (pwd !== rpwd){
                $('#tipsRuserPassword').text("*密码不一致");
            }else{
                $('#tipsRuserPassword').text("");
            }
        }
    </script>

</body>
</html>
